function getChangeXml(val, chart_name) {
	var chart = new FusionCharts("../chart/Column2D.swf", "ChartId", "830",
			"300", "0", "0");
	jQuery.ajax({
		type : "post",
		url : "../trend/changexml?value=" + val,
		success : function(msg) {
			chart.setDataXML(msg);
			chart.addParam("wmode", "transparent");
			chart.render(chart_name);
		}
	});
}

function setTab(name, cursel, n) {
	for (var i = 1; i <= n; i++) {
		var menu = document.getElementById(name + i);
		var con = document.getElementById("con_" + name + "_" + i);
		menu.className = i == cursel ? "hover" : "";
		con.style.display = i == cursel ? "block" : "none";
	}
}

function getFlash(val) {
	var tys = new Array();
	var tim = new Array();
	if (document.getElementById('pv')) {
		if (document.getElementById('pv').checked == true)
			tys[tys.length] = 'pv';
	}
	if (document.getElementById('ip')) {
		if (document.getElementById('ip').checked == true)
			tys[tys.length] = 'ip';
	}
	if (document.getElementById('uv')) {
		if (document.getElementById('uv').checked == true)
			tys[tys.length] = 'uv';
	}
	if (document.getElementById('newuser')) {
		if (document.getElementById('newuser').checked == true)
			tys[tys.length] = 'newuser';
	}
	if (document.getElementById('monthtoday')) {
		if (document.getElementById('monthtoday').checked == true)
			tim[tim.length] = 'monthtoday';
	}
	if (document.getElementById('weektoday')) {
		if (document.getElementById('weektoday').checked == true)
			tim[tim.length] = 'weektoday';
	}
	if (document.getElementById('yesterday')) {
		if (document.getElementById('yesterday').checked == true)
			tim[tim.length] = 'yesterday';
	}
	if (tys.length == 0) {
		return;
	}
	var s = tys.join();
	var so = new FusionCharts("../chart/MSLine.swf?", "ChartId", "830", "260");
	jQuery.ajax({
		type : "post",
		url : "../trend/changelinexml?day=" + tim + "&keyid=" + s + "&time="
				+ val,
		success : function(msg) {
			so.setDataXML(msg);
			so.addParam("wmode", "transparent");
			so.render("flashcontent");
		}
	});
}

function getFlash30(val, val2) {

	var tys = new Array();
	if (document.getElementById('pv')) {
		if (document.getElementById('pv').checked == true)
			tys[tys.length] = 'pv';
	}
	if (document.getElementById('ip')) {
		if (document.getElementById('ip').checked == true)
			tys[tys.length] = 'ip';
	}
	if (document.getElementById('uv')) {
		if (document.getElementById('uv').checked == true)
			tys[tys.length] = 'uv';
	}
	if (document.getElementById('newuser')) {
		if (document.getElementById('newuser').checked == true)
			tys[tys.length] = 'newuser';
	}

	if (tys.length == 0) {
		return;
	}
	var s = tys.join();
	var so = new FusionCharts("../chart/MSLine.swf?", "ChartId", "830", "260");
	jQuery.ajax({
		type : "post",
		url : "../trend/changeLineXml30?keyid=" + s + "&startTime=" + val
				+ "&endTime=" + val2,
		success : function(msg) {
			so.setDataXML(msg);
			so.addParam("wmode", "transparent");
			so.render("chartdiv");
		}
	});
}

// 获取本月
function getFlashTomonth(val, val2) {

	var tys = new Array();
	if (document.getElementById('pv')) {
		if (document.getElementById('pv').checked == true)
			tys[tys.length] = 'pv';
	}
	if (document.getElementById('ip')) {
		if (document.getElementById('ip').checked == true)
			tys[tys.length] = 'ip';
	}
	if (document.getElementById('uv')) {
		if (document.getElementById('uv').checked == true)
			tys[tys.length] = 'uv';
	}
	if (document.getElementById('newuser')) {
		if (document.getElementById('newuser').checked == true)
			tys[tys.length] = 'newuser';
	}

	if (tys.length == 0) {
		return;
	}
	var s = tys.join();
	var so = new FusionCharts("../chart/MSLine.swf?", "ChartId", "830", "260");
	jQuery.ajax({
		type : "post",
		url : "../trend/changeLineXmlTomonth?keyid=" + s + "&startTime=" + val
				+ "&endTime=" + val2,
		success : function(msg) {
			so.setDataXML(msg);
			so.addParam("wmode", "transparent");
			so.render("chartdiv");
		}
	});
}
function getsearch() {
	var date_arr = $('#inputDate').val().split("至");
	date_search(date_arr[0], date_arr[1]);
}


function date_search(from, to) {
	if (to.length == 0 || from.length == 0) {
		return;
	}
	if (compare_date(from, to)) {
		location.href = '../trend/yesterday?time=' + from+'&endtime='+to;
	}
}

//用户忠诚度分析
function getsearchUserLoyal(obj) {
	var date_arr = $('#inputDate').val().split("至");
	date_searchUserLoyal(date_arr[0], date_arr[1],obj);
}

//忠诚度分析
function date_searchUserLoyal(from, to, obj) {
	if (to.length == 0 || from.length == 0) {
		return;
	}
	if (compare_date(from, to)) {
		location.href = obj+'?time=' + from+'&endtime='+to;
	}
}



function compare_date(a, b) {
	var pattern = /^\d{4}-\d{2}-\d{2}$/;
	var arr = a.split("-");
	var starttime = new Date(arr[0], arr[1] - 1, arr[2]);
	var starttimes = starttime.getTime();
	var arrs = b.split("-");
	var lktime = new Date(arrs[0], arrs[1] - 1, arrs[2]);
	var lktimes = lktime.getTime();

	var _add_stat_time = "2012-05-01";// 流量统计开始日期
	var _arrs = _add_stat_time.split("-");
	var _lktime = new Date(_arrs[0], _arrs[1] - 1, _arrs[2]);
	var _add_stat_time2 = _lktime.getTime();

	var t = new Date;
	var r = {};
	r.year = t.getFullYear();
	r.month = t.getMonth();
	r.day = t.getDate();
	var today = new Date(r.year, r.month, r.day);
	today = today.getTime();
	if (pattern.test(a) == false) {
		alert("日期输入有误，请重新输入");

		return false;
	} else if (pattern.test(b) == false) {
		alert("日期输入有误，请重新输入");

		return false;
	} else if (starttimes > lktimes) {
		alert('日期输入错误。');

		return false;
	} else if (starttimes < _add_stat_time2) {
		alert('开始时间不能早于统计开通时间！');

		return false;
	} else if (today < starttimes) {
		alert('日期输入错误。');

		return false;
	} else if (today < lktimes) {
		alert('日期输入错误。');

		return false;
	}
	return true;
}

function getShow(data) {

	var date_arr = $('#inputDate').val().split("至");
	datashow(data,date_arr[0], date_arr[1]);
}

function datashow(data,from, to) {
	if (to.length == 0 || from.length == 0) {
		return;
	}
	if (compare_date(from, to)) {
		location.href = data+"=" + from+"&toDate="+to+"&number=1";
	}
}

//来路域名图表
function getPieXml(val) {
	var date_arr =val.split("至");
	var chart = new FusionCharts("../chart/Pie2D.swf", "ChartId", "830",
			"300", "0", "0");
	jQuery.ajax({
		type : "post",
		url : "../domain/piexml?fromDate=" + date_arr[0]+"&toDate="+date_arr[1],
		success : function(msg) {
			chart.setDataXML(msg);
			chart.addParam("wmode", "transparent");
			chart.render("chartdiv");
		}
	});
}

function getCategoryType()
{
	var val = $('#inputDate').val();
	var date_arr =val.split("至");
	var tys = new Array();
	if (document.getElementById('engineId')) {
		if (document.getElementById('engineId').checked == true)
			tys[tys.length] = 'engineId';
	}
	if (document.getElementById('externalId')) {
		if (document.getElementById('externalId').checked == true)
			tys[tys.length] = 'externalId';
	}
	if (document.getElementById('directId')) {
		if (document.getElementById('directId').checked == true)
			tys[tys.length] = 'directId';
	}
	var s = tys.join();
	var so = new FusionCharts("../chart/MSLine.swf?", "ChartId", "830", "260");
	jQuery.ajax({
		type : "post",
		url : "../domain/changelinexmlByDomain?keyid=" + s + "&formDate="
				+ date_arr[0]+"&toDate="+date_arr[1],
		success : function(msg) {
			so.setDataXML(msg);
			so.addParam("wmode", "transparent");
			so.render("chartdiv");
		}
	});
	}

//加载来路域名图表的JS
function getHistoryXml(type)
{
	var fromDate = $('#fromDate').val();
	var toDate = $('#toDate').val();
	var domainName = $('#domainName').val();
	var chart = new FusionCharts("../chart/Column2D.swf", "ChartId", "830",
			"300", "0", "0");
	jQuery.ajax({
		type : "post",
		url : "../domain/historyxml?value=" + type+"&fromDate="+fromDate+"&toDate="+toDate+"&domainName="+domainName,
		success : function(msg) {
			chart.setDataXML(msg);
			chart.addParam("wmode", "transparent");
			chart.render("chartdiv");
		}
	});
}

//加载来路页面图表的JS
function getPageXml(type)
{
	var fromDate = $('#fromDate').val();
	var toDate = $('#toDate').val();
	var pageName = $('#pageName').val();
	var chart = new FusionCharts("../chart/Column2D.swf", "ChartId", "830",
			"300", "0", "0");
	jQuery.ajax({
		type : "post",
		url : "../domain/pagexml?value=" + type+"&fromDate="+fromDate+"&toDate="+toDate+"&pageName="+pageName,
		success : function(msg) {
			chart.setDataXML(msg);
			chart.addParam("wmode", "transparent");
			chart.render("chartdiv");
		}
	});
}

//加载来路分类 图表的JS
function getCategoryXml(type)
{
	var fromDate = $('#fromDate').val();
	var toDate = $('#toDate').val();
	var chart = new FusionCharts("../chart/Column2D.swf", "ChartId", "830",
			"300", "0", "0");
	jQuery.ajax({
		type : "post",
		url : "../domain/categoryxml?value=" + type+"&fromDate="+fromDate+"&toDate="+toDate,
		success : function(msg) {
			chart.setDataXML(msg);
			chart.addParam("wmode", "transparent");
			chart.render("chartdiv");
		}
	});
}
function changecss()
{
   var strtm = $('#type').val();
   
   if(strtm == 1)
   {
    $('#todayId').attr("style","background:#5C7AA0;");
	$('#todayIda').attr("style","color:white;");
   }
   if(strtm == 2)
   {
    $('#yesterdayId').attr("style","background:#5C7AA0;");
	$('#yesterdayIda').attr("style","color:white;");
   }
   if(strtm == 3)
   {
    $('#tomonthId').attr("style","background:#5C7AA0;");
	$('#tomonthIda').attr("style","color:white;");
   }
    if(strtm == 4)
   {
    $('#latemonthId').attr("style","background:#5C7AA0;");
	$('#latemonthIda').attr("style","color:white;");
   }
}

//加载来路页面图表的JS
function getVisitAreaXml(type)
{
	var fromDate = $('#fromDate').val();
	var toDate = $('#toDate').val();
	var province = $('#province').val();
	var chart = new FusionCharts("../chart/Column2D.swf", "ChartId", "830",
			"300", "0", "0");
	jQuery.ajax({
		type : "post",
		url : "../visitarea/visithistoryxml?value=" + type+"&fromDate="+fromDate+"&toDate="+toDate+"&province="+province,
		success : function(msg) {
			chart.setDataXML(msg);
			chart.addParam("wmode", "transparent");
			chart.render("chartdiv");
		}
	});
}
function getOperatorXml(type)
{
	var fromDate = $('#fromDate').val();
	var toDate = $('#toDate').val();
	var operator = $('#operator').val();
	var chart = new FusionCharts("../chart/Column2D.swf", "ChartId", "830",
			"300", "0", "0");
	jQuery.ajax({
		type : "post",
		url : "../operator/operatorhistoryxml?value=" + type+"&fromDate="+fromDate+"&toDate="+toDate+"&operatorName="+operator,
		success : function(msg) {
			chart.setDataXML(msg);
			chart.addParam("wmode", "transparent");
			chart.render("chartdiv");
		}
	});
}

function getBrowserXml(type)
{
	var fromDate = $('#fromDate').val();
	var toDate = $('#toDate').val();
	var browserName = $('#browserName').val();
	var chart = new FusionCharts("../chart/Column2D.swf", "ChartId", "830",
			"300", "0", "0");
	jQuery.ajax({
		type : "post",
		url : "../browser/browserhistoryxml?value=" + type+"&fromDate="+fromDate+"&toDate="+toDate+"&browserName="+browserName,
		success : function(msg) {
			chart.setDataXML(msg);
			chart.addParam("wmode", "transparent");
			chart.render("chartdiv");
		}
	});
}
